<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="cs.utils.DBUtils" %>
<%@ page import="cs.entity.UserInfo" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    session.setAttribute("bpath", basePath);

    String search = request.getParameter("search");

    List<UserInfo> list = DBUtils.query(search);
    List<Integer> list1 = DBUtils.queryCount();

    if (null == request.getAttribute("msg") || "".equals(request.getAttribute("msg"))) {
        request.setAttribute("msg", "");
    }
    session.setAttribute("userinfo", null);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>员工薪资管理系统</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>
    <style type="text/css">
        .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th{
            line-height: 3;
        }
    </style>
</head>
<body>
<div style="padding: 50px">
    <div style="width: 100%;height: 100px;display: flex;align-items: center;justify-content: center;text-align: center;">
        <h1>员工薪资管理系统</h1>
    </div>

    <div style="width: 100%;height: 100px;display: flex;justify-content: flex-end;padding: 0 100px">

        <button style="width: 80px;height: 40px;margin-right: 20px;" type="button" class="btn btn-primary"
                data-target="#statisticalId" data-toggle="modal">统计
        </button>

        <form action="index.jsp" method="get" style="display: flex">
            <select class="form-control" style="width: 90px;height: 40px;margin-right: 20px;" name="search">
                <option></option>
                <option>经理室</option>
                <option>财务科</option>
                <option>技术科</option>
                <option>销售科</option>
            </select>

            <button style="width: 80px;height: 40px;margin-right: 20px;" type="submit" class="btn btn-primary"
            >刷新
            </button>
        </form>

        <button style="width: 80px;height: 40px" type="button" class="btn btn-primary"
                data-target="#myModal" data-toggle="modal">录入员工
        </button>
    </div>

    <table class="table table-hover table-striped">
        <thead>
        <tr>
            <th>id</th>
            <th>名称</th>
            <th>性别</th>
            <th>年龄</th>
            <th>单位</th>
            <th>职业</th>
            <th>基本工资</th>
            <th>福利工资</th>
            <th>奖励工资</th>
            <th>失业保险</th>
            <th>住房公积金</th>
            <th>科室</th>
            <th>实际应发工资</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <%for (int i = 0; i < list.size(); i++) {%>
        <tr>
            <th><%=list.get(i).getId()%>
            </th>
            <th><%=list.get(i).getName()%>
            </th>
            <th><%=list.get(i).getSex()%>
            </th>
            <th><%=list.get(i).getAge()%>
            </th>
            <th><%=list.get(i).getUnit()%>
            </th>
            <th><%=list.get(i).getProfessional()%>
            </th>
            <th><%=list.get(i).getBasicSalary()%>
            </th>
            <th><%=list.get(i).getWelfare()%>
            </th>
            <th><%=list.get(i).getReward()%>
            </th>
            <th><%=list.get(i).getUnemploymentInsurance()%>
            </th>
            <th><%=list.get(i).getHousingProvidentFund()%>
            </th>
            <th><%=list.get(i).getDepartment()%>
            </th>
            <th><%=list.get(i).getAmount()%>
            </th>
            <th>
                <form action="/delete" method="post">
                    <input type="hidden" name="id" value="<%=list.get(i).getId()%>">
                    <button type="submit" class="btn btn-danger btn-sm">删除</button>
                </form>
            </th>
        </tr>
        <% }%>
        </tbody>

    </table>

    <div class="modal fade" id="statisticalId" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">统计</h4>
                </div>
                <div class="modal-body">
                    <div>经理室人数：<%=list1.get(0)%></div>
                    <div>财务科人数：<%=list1.get(1)%></div>
                    <div>技术科人数：<%=list1.get(2)%></div>
                    <div>销售科人数：<%=list1.get(3)%></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="myModal" tabindex="-1">
        <form action="/addUser" method="post">
            <div class="modal-dialog modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">录入员工</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label>名称</label>
                            <input type="text" class="form-control" name="name" placeholder="请输入名称">
                        </div>
                        <div class="form-group">
                            <label>性别
                                <label class="radio-inline">
                                    <input type="radio" name="sex" id="inlineRadio1" value="男"> 男
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="sex" id="inlineRadio2" value="女"> 女
                                </label>
                            </label>
                        </div>

                        <div class="form-group">
                            <label>年龄</label>
                            <input type="number" name="age" class="form-control" placeholder="请输入年龄">
                        </div>
                        <div class="form-group">
                            <label>单位</label>
                            <input type="text" name="unit" class="form-control" placeholder="请输入单位">
                        </div>
                        <div class="form-group">
                            <label>职业</label>
                            <input type="text" name="professional" class="form-control" placeholder="请输入职业">
                        </div>
                        <div class="form-group">
                            <label>基本工资</label>
                            <input type="number" name="basicSalary" class="form-control" placeholder="请输入基本工资">
                        </div>
                        <div class="form-group">
                            <label>福利工资</label>
                            <input type="number" name="welfare" class="form-control" placeholder="请输入福利工资">
                        </div>
                        <div class="form-group">
                            <label>奖励工资</label>
                            <input type="number" name="reward" class="form-control" placeholder="请输入奖励工资">
                        </div>
                        <div class="form-group">
                            <label>失业保险</label>
                            <input type="number" name="unemploymentInsurance" class="form-control"
                                   placeholder="请输入失业保险">
                        </div>
                        <div class="form-group">
                            <label>住房公积金</label>
                            <input type="number" name="housingProvidentFund" class="form-control"
                                   placeholder="请输入住房公积金">
                        </div>
                        <div class="form-group">
                            <label>科室</label>
                            <select class="form-control" name="department">
                                <option>经理室</option>
                                <option>财务科</option>
                                <option>技术科</option>
                                <option>销售科</option>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">录入</button>
                    </div>
                </div>
            </div>
        </form>
    </div>


</div>

<script type="text/javascript">
    // window.location.href = "deleteSuccess.jsp";

</script>
</body>
</html>
